<?php
include("function.php");
checklogin();

$picture=$_GET['picture'];
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
		$type = strtolower(substr(strrchr($picture,"."),1));	//获取图片类型
		$avatar="cache/avatar_200".$_SESSION['login_mail'].".".$type;
		$targ_w = $targ_h = 200;
		$jpeg_quality = 90; 	
		$src = $picture;
		$img_r = imagecreatefromjpeg($src);
		$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );	
		imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);

		//输出新图片
		if($type == 'jpeg' || $type == 'jpg'){
			imagejpeg($dst_r,$avatar);
		}elseif($type == 'gif'){
			imagegif($dst_r,$avatar);
		}elseif($type == 'png'){
			imagepng($dst_r,$avatar);
		}elseif($type == 'bmp'){
			imagebmp($dst_r,$avatar);//bmp.php中包含
		}
		unlink($picture);
		echo "<script language=\"javascript\">location.href='edit_user_info.php?avatar=2&type=$type';</script>";
		//imageStorage($avatar);
}
	

$result=mysql_query("select * from user where user_email='$_SESSION[login_mail]'");
$r=mysql_fetch_array($result);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" /><!--如果是IE8时强制以IE7显示-->
<meta name="keywords" content=""><!--SEO关键字-->
<meta name="description" content=""><!--SEO描述-->
<link rel ="" href=""><!--选项卡图标-->
<title><?php echo $r['user_name']."——个人信息修改";?></title>
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/edit_user_info.js"></script>
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/jquery.Jcrop.js" type="text/javascript"></script>
<script type="text/javascript" src="js/script.js"></script>
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css" />
<link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

</head>


<body>
	
	<?php include("include/header.php");?>
	
	<div class="user_ico">
		<img class="u_ico" src="img/user_ico.gif" alt="" /><p>账号设置</p>
	</div>
	<div class="user_main">
		<div class="user_menu"><!-- 菜单 -->
			<div class="title dib">个人资料</div>
			<ul class="dib">
				<li><a class="dib title_current" href="#" id="info_link">基本信息</a></li>
				<li><a class="dib"  href="#" id="pwd_link">修改密码</a></li>
				<li><a class="dib"  href="#" id="avatar_link">修改头像</a></li>
			</ul>
		</div>
		
		<div class="article" style="display:none">
      	<img src="<?php echo $picture;?>" id="jc-hidden-image" >
      	<button class="ui-button" id="jc-dyn-btn">Dynamic Dialog</button>
			</div>
		
		<!--个人基本信息-->
	
		<div class="user_message" id="edit_info">
			<div class="user_me_head">
				<h3>基本信息</h3>	
				<p>以下信息将显示在个人资料页，方便大家了解你。</p>		
			</div>
			<div class="me_info">
				<!--修改提示-->
				<div id="main_message"></div>
				<ul>
					<li><label for="" class="a">ID：</label><span class="b"><?php echo $r['u_id'];?></span></li>
					<li><label for="" class="a">登录邮箱：</label><span class="b"><?php echo $r['user_email'];?></span></li>
					<li><label for="" class="a">*昵称：</label><span class="b"><div class="me_input dib"><input type="text" value="<?php echo $r['user_name'];?>" id="user_name"/></div></span></li>
					<li><label for="" class="a">真实姓名：</label><span class=""><div class="me_input dib"><input type="text" value="<?php echo $r['true_name'];?>" id="true_name"/></div></span></li>
					<li><label for="" class="a">性别：</label>
						<span class="b">
							<select id="selSex">
							<?php if($r['sex']==0){
								echo "<option value='0' selected>男</option>";
								echo "<option value='1'>女</option>";
							}else{
								echo "<option value='0'>男</option>";
								echo "<option value='1' selected>女</option>";
								}
							?>
						</select>
						</span>
					</li>
					<li><label for="" class="a">出生年月：</label>
						<span class="b">
							<select id="selYear" name="birth_year">
							<option value="0">请设置</option>
								<?php
								$year=substr($r['birthday'],0,4);
								$month=substr($r['birthday'],5,2);
								$day=substr($r['birthday'],8,2);
								for($i=1900;$i<=2012;$i++){
									if($i==$year){echo "<option value='$i' selected>".$i."年</option>";continue;}
									echo "<option value='$i'>".$i."年</option>";
									}
								?>
							</select>
							<select id="selMonth" name="birth_month">
								<?php
								for($i=1;$i<=12;$i++){
									if($i==$month){echo "<option value='$i' selected>".$i."月</option>";continue;}
									echo "<option value='$i'>".$i."月</option>";
									}
								?>
								
							</select>
							<select id="selDate" name="birth_day">
								<?php
								for($i=1;$i<=31;$i++){
									if($i==$day){echo "<option value='$i' selected>".$i."日</option>";continue;}
									echo "<option value='$i'>".$i."日</option>";
									}
								?>
								
							</select>
							
						</span>
					</li>
					<li><label for="" class="a">所在地：</label>
						<span class="b">
							<span class="v">
								<select id="province" name="province" defaultvalue="湖南省">
									<option value="<?php echo $r['province'];?>"><?php echo $r['province'];?></option>
									<option value="北京">北京</option>
									<option value="上海">上海</option>
									<option value="天津">天津</option>
									<option value="重庆">重庆</option>
									<option value="安徽省">安徽省</option>
									<option value="福建省">福建省</option>
									<option value="甘肃省">甘肃省</option>
									<option value="广东省">广东省</option>
									<option value="广西壮族自治区">广西壮族自治区</option>
									<option value="贵州省">贵州省</option>
									<option value="海南省">海南省</option>
									<option value="河北省">河北省</option>
									<option value="河南省">河南省</option>
									<option value="黑龙江省">黑龙江省</option>
									<option value="湖北省">湖北省</option>
									<option value="湖南省">湖南省</option>
									<option value="吉林省">吉林省</option>
									<option value="江苏省">江苏省</option>
									<option value="江西省">江西省</option>
									<option value="辽宁省">辽宁省</option>
									<option value="内蒙古自治区">内蒙古自治区</option>
									<option value="宁夏回族自治区">宁夏回族自治区</option>
									<option value="青海省">青海省</option>
									<option value="山东省">山东省</option>
									<option value="山西省">山西省</option>
									<option value="陕西省">陕西省</option>
									<option value="四川省">四川省</option>
									<option value="西藏自治区">西藏自治区</option>
									<option value="新疆维吾尔自治区">新疆维吾尔自治区</option>
									<option value="云南省">云南省</option>
									<option value="浙江省">浙江省</option>
									<option value="香港特别行政区">香港特别行政区</option>
									<option value="澳门特别行政区">澳门特别行政区</option>
									<option value="台湾省">台湾省</option>
									<option value="海外">海外</option>
								</select>
								<!--市-->
								<select id="city" name="city">
									<option value="<?php echo $r['city'];?>"><?php echo $r['city'];?></option>
								</select>

							</span>
						</span>						
						</span>
					</li>
					<li><label for="" class="a">简介：</label><span class="b"><textarea class="me_text solid" id="remark" ><?php echo $r['remark'];?></textarea></span></li>
				</ul>
				<div class="dib save">					
					<input type="submit" value="保&nbsp&nbsp存" class="post_button dib" id="submit_main">
				</div>
			</div>
		</div>
			
			
			<!--修改头相--->
			
			<div class="user_message" id="edit_avatar" style="display:none">
			<div class="user_me_head">
				<h3>修改头像</h3>	
			</div>
			<div class="me_info">
					<!--提示信息-->
					<div id="avatar_message"></div>					
				<div class="me_head">
					<div class="login_button" ><a href="#" class="lo_re_bo dib" id="buttom_upload">上&nbsp传&nbsp头&nbsp像</a></div>
					<div class="me_he_img">
						<div class="img_b"><img style="width:210px; height:210px;" src="<?php if($_GET['avatar']==""){echo showUserAvatar($_SESSION['login_mail']);}else{echo "cache/avatar_200".$_SESSION['login_mail'].".".$_GET['type'];}?>" alt="" id="ajax_avatar"/></div>
						<div class="img_s">
							<img style="width:100px; height:100px;" src="<?php if($_GET['avatar']==""){echo showUserAvatar($_SESSION['login_mail']);}else{echo "cache/avatar_200".$_SESSION['login_mail'].".".$_GET['type'].'?math='.rand(0,100000);}?>" alt="" />
							<p>100*100像素</p>
							<img style="width:50px; height:50px;" src="<?php if($_GET['avatar']==""){echo showUserAvatar($_SESSION['login_mail']);}else{echo "cache/avatar_200".$_SESSION['login_mail'].".".$_GET['type'].'?math='.rand(0,100000);}?>" alt="" />
							<p>50*50像素</p>
						</div>
						
					</div>
				</div>
				
				<!--上传部分-->
				
				<div style="display:none">	
					<form method="post" action ="upload_avatar.php" enctype="multipart/form-data" class="none">
							<input type="file" name="up_image" id="photo"/>
							<input type="submit" name="p_submit" value="保存" id="p_submit">
					</form>
				</div>

				<div class="sa_co">
					<div class="dib head_save">					
						<input type="submit" value="保&nbsp&nbsp存" class="qh_bo dib" id="submit_avatar">
					</div>	
					<div class="dib head_save">					
						<input type="submit" value="取&nbsp&nbsp消" class="qh_bo dib">
					</div>
	
				</div>
			
			</div>		
		</div>

		<!---修改密码-->
		
		<div class="user_message" id="edit_pwd" style="display:none">
			<div class="user_me_head">
				<h3>修改密码</h3>	
			</div>
			<div class="me_info">
					<!--提示信息-->
					<div id="pwd_message" style=""></div>			
				<ul>
					<li><label for="" class="a">当前密码：</label><span class="b"><div class="me_input dib"><input type="password" id="pwd_old"/></div></span></li>
					<li><label for="" class="a">新密码：</label><span class=""><div class="me_input dib"><input type="password" id="pwd_new"/></div></span></li>
					<li><label for="" class="a">确认密码：</label><span class=""><div class="me_input dib"><input type="password" id="pwd_new1"/></div></span></li>
				</ul>
				<div class="dib save">					
					<input type="submit" value="保&nbsp&nbsp存" class="post_button dib" id="submit_pwd">


				</div>		
			</div>	
		</div>
		
		
			
		
		
	</div>
	<hr class="hr mt30" >
	<div class="copyright w960 ma">关于我们&nbsp|&nbsp使用条款&nbsp|&nbsp常见问题<br/>CopyRight &copy; 2011-2012 <a href="http://www.csecl.com/">csecl.com复杂系统与电子商务创新实验室</a> </div>
	


</body>
</html>